<?php

	$param_report = strtolower($_GET["report"]);

	require_once("includes/config.php");
	require_once("includes/functions.php");
	require_once("classes/class.Team.php");
	require_once("classes/class.Field.php");
	require_once("classes/class.User.php");
	require_once("classes/class.Metric.php");
	require_once("classes/phpreports/PHPReportMaker.php");
	
	include("export.php");
	
	if($param_report=="") { $param_report="default"; }
	$param_report = "reports/" . $param_report . ".xml";
	
	$xml_report = simplexml_load_file($param_report);
	$xmlSQL = $xml_report->SQL;
		
	//$sSQL = "select *, DATE_FORMAT(datestamp,'%Y-%d') AS monthstamp from report;";
	$sSQL = "SELECT report.*, user.user_name AS user_name, team.team_description AS team_description, DATE_FORMAT(report.datestamp,'%Y-%d') AS monthstamp, DATE_FORMAT(report.datestamp,'%Y') AS yearstamp FROM report LEFT JOIN (team, user) ON (team.team_name = report.team_name AND user.user_id = report.user_id)";
	$sSQL .= $xmlSQL . ";";

	$oRpt = new PHPReportMaker();

	$oRpt->setXML($param_report);
	$oRpt->setUser("root");
	$oRpt->setPassword("M0nk3yDu5t");
	$oRpt->setConnection("localhost");
	$oRpt->setDatabaseInterface("mysql");
	$oRpt->setSQL($sSQL);
	$oRpt->setDatabase("metrix");
	$oRpt->run();
	
?>
